home *** CD-ROM | disk | FTP | other *** search
/ How Would You Survive? / How Would You Survive (1995)(Grolier)[Mac-PC].iso / mac / EINDEX.DIR / 00707_Script_aTopicMenu < prev    next >
Text File  |  1995-09-06  |  8KB  |  207 lines

  1. --òò aTopicMenu
  2. --òò This object represents an entry in the Alabetical Index System
  3. --òò In otherwords we need to create one of these objects per
  4. --òò Letter in the alphabet. This object in turn manages a sub-menu
  5. --òò of entries associated with the Letter. Each sub-menu entry
  6. --òò manages a list of links to locations in the subject screens
  7. --òò of the title.
  8. property pHilightCast, pSprite , pDefaultCast , pRange┬
  9.        , pRefLink , pLeftEntries, pRightEntries , pEndOFLine  , pLineSpace
  10. on birth me , startCast , stopCast , theSprite , theDefaultCast┬
  11.             , functionCast ,iconCast  ,numLeftEntries, newRightEntries
  12.   setTopicMenuParameters me , numLeftEntries, newRightEntries
  13.   set pLineSpace = 25
  14.   set pDefaultCast = theDefaultCast 
  15.   if (startCast) then
  16.     set pHilightCast = startCast 
  17.   else
  18.     set pHilightCast = pDefaultCast
  19.   end if
  20.   set pRange = stopCast - startCast + 1
  21.   set pSprite = theSprite
  22.   
  23.   set refCountMax = numLeftEntries + newRightEntries 
  24.   set refCount = 1
  25.   set pRefLink = []
  26.   set pEndOFLine = FALSE
  27.   set refLinkClass = the number of cast "aRefLink"
  28.   repeat while (refCount <= refCountMax)
  29.     setAt( pRefLink ,refCount, birth (script refLinkClass, iconCast + refCount - 1 ,40┬
  30.         ,1 ,functionCast))
  31.     set refCount = refCount + 1
  32.   end repeat
  33.   
  34.   return me
  35. end
  36.  
  37. on setTopicMenuParameters me , numLeftEntries, newRightEntries
  38.   set pRightEntries = newRightEntries
  39.   set pLeftEntries = numLeftEntries
  40. end
  41.  
  42. on setTopicMenu me
  43.   if (pSprite > 0) then
  44.     set the castNum of sprite pSprite = pHilightCast 
  45.   else
  46.     set the castNum of sprite pSprite = pDefaultCast
  47.   end if
  48. end
  49.  
  50. on setTopicHiLight me , theOffset
  51.   if (pRightEntries and rollover(41)) then
  52.     -- right entry processing
  53.     set topicOffset =  theOffset/pLineSpace
  54.     if (topicOffset <= pRange) then 
  55.       set the castNum of sprite pSprite = pHilightCast + topicOffset - 1 + pLeftEntries
  56.     end if
  57.   else
  58.     -- left entry processing
  59.     set topicOffset =  theOffset/pLineSpace
  60.     if (topicOffset <= pRange) then 
  61.       set the castNum of sprite pSprite = pHilightCast + topicOffset - 1 
  62.     end if 
  63.   end if
  64. end
  65.  
  66. --òò Ref Link handlers
  67. on selectTopicFromMenu me,theOffset
  68.   if (theOffset > 62) then 
  69.     set theOffset = theOffset - 62
  70.     set topicOffset =  (theOffset/pLineSpace) + 1
  71.     --put theOffset , topicOffset
  72.     if (pRightEntries and rollover(41)) then
  73.       -- right entry processing
  74.       if (topicOffset > 0 and topicOffset <= pRightEntries) then
  75.         set thisLink = getAt(pRefLink,topicOffset + pLeftEntries) 
  76.       end if
  77.     else
  78.       -- left entry processing
  79.       if (topicOffset > 0 and topicOffset <= pLeftEntries) then
  80.         set thisLink = getAt(pRefLink,topicOffset) 
  81.       end if
  82.     end if
  83.     showRefLinkIcon(thisLink) 
  84.   end if
  85. end
  86.  
  87. on clickRefLink me , theOffset , horzPos , vertPos
  88.   set pEndOFLine = FALSE
  89.   --put vertPos ,horzPos
  90.   --set thisLink = getAt(pRefLink,1)
  91.   --clickRefLink(thisLink , theOffset)
  92.   set thisCast = the castNum of sprite 40
  93.   set thisStr = the scriptText of cast thisCast
  94.   set thisLength = length(thisStr)
  95.   set strCount = 3
  96.   set commaPos1 = getCommaPos (me, thisStr , strCount , thisLength)
  97.   set commaPos2 = getCommaPos (me, thisStr , commaPos1 + 1, thisLength)
  98.   set commaPos3 = getCommaPos (me, thisStr , commaPos2 + 1, thisLength)
  99.   set commaPos4 = getCommaPos (me, thisStr , commaPos3 + 1, thisLength)
  100.   if (getRecPos (me, thisStr , 3 , commaPos1 ) = 0) then
  101.     -- this is simple (one ref) reference
  102.     --beep 1
  103.     --put 1
  104.     do getFunctionStr (me, thisStr , commaPos4 , thisLength ) 
  105.   else
  106.     -- test if click is inside of rect
  107.     set pEndOFLine = FALSE
  108.     set startStr = 2
  109.     set beepCount = 1
  110.     repeat while (pEndOFLine = FALSE)
  111.       --testClick me,commaPos1,commaPos2,commaPos3,commaPos4 , ┬
  112.           thisStr , thisLength , horzPos , vertPos
  113.       if (testClick(me,startStr,commaPos1,commaPos2,commaPos3 ┬
  114.                  , thisStr , thisLength, horzPos , vertPos)) then 
  115.         -- get function
  116.         set pEndOFLine = TRUE
  117.         --beep beepCount
  118.         --put beepCount
  119.         do getFunctionStr (me, thisStr , commaPos4 , thisLength )
  120.       else
  121.         -- move past function
  122.         set semiColPos = getSemiCol  (me, thisStr , commaPos4 + 1 , thisLength)
  123.         set commaPos1 = getCommaPos (me, thisStr , semiColPos + 1 , thisLength)
  124.         set commaPos2 = getCommaPos (me, thisStr , commaPos1 + 1, thisLength)
  125.         set commaPos3 = getCommaPos (me, thisStr , commaPos2 + 1, thisLength)
  126.         set commaPos4 = getCommaPos (me, thisStr , commaPos3 + 1, thisLength)
  127.         set startStr = semiColPos
  128.         set beepCount = beepCount + 1
  129.       end if 
  130.     end repeat
  131.   end if
  132. end
  133.  
  134. on clearRefLinkIcon me
  135.   if (not(pRefLink = []) ) then
  136.     set thisLink = getAt(pRefLink,1)
  137.     clearRefLinkIcon(thisLink) 
  138.   end if
  139. end
  140.  
  141. on getSemiCol  me , thisStr , strCount , thisLength
  142.   --òò This handler returns the position of the next comma, or the end of the string
  143.   set thisChar = chars(thisStr,strCount,strCount)
  144.   if (thisChar = "%") then set pEndOFLine = TRUE
  145.   repeat while (not(thisChar = ";") and strCount < thisLength) 
  146.     set strCount = strCount + 1
  147.     set thisChar = chars(thisStr,strCount,strCount)
  148.     if (thisChar = "%") then set pEndOFLine = TRUE
  149.   end repeat
  150.   return strCount
  151. end
  152.  
  153. on getCommaPos me , thisStr , strCount , thisLength
  154.   --òò This handler returns the position of the next comma, or the end of the string
  155.   set thisChar = chars(thisStr,strCount,strCount)
  156.   if (thisChar = "%") then set pEndOFLine = TRUE
  157.   repeat while (not(thisChar = ",") and strCount < thisLength) 
  158.     set strCount = strCount + 1
  159.     set thisChar = chars(thisStr,strCount,strCount)
  160.     if (thisChar = "%") then set pEndOFLine = TRUE
  161.   end repeat
  162.   return strCount
  163. end
  164.  
  165. on getRecPos me , thisStr , strCount , thisLength
  166.   set intCount = strCount
  167.   set thisChar = chars(thisStr,strCount,strCount)
  168.   repeat while (not(thisChar = ",") and strCount < thisLength) 
  169.     set strCount = strCount + 1
  170.     set thisChar = chars(thisStr,strCount,strCount)
  171.   end repeat
  172.   return (chars (thisStr , intCount , strCount - 1))
  173. end
  174.  
  175. on getFunctionStr me, thisStr , strCount , thisLength
  176.   set intCount = strCount
  177.   set thisChar = chars(thisStr,strCount,strCount)
  178.   repeat while (not(thisChar = ";") and strCount < thisLength) 
  179.     set strCount = strCount + 1
  180.     set thisChar = chars(thisStr,strCount,strCount)
  181.   end repeat
  182.   return (chars (thisStr , intCount + 1 , strCount - 1))
  183. end
  184.  
  185. on testClick me,commaPos1,commaPos2,commaPos3,commaPos4 , thisStr , thisLength , horzPos , vertPos
  186.   set topPos = getRecPos (me , thisStr , commaPos1 + 1 , thisLength)
  187.   set leftPos =  getRecPos (me , thisStr , commaPos2 + 1 , thisLength)
  188.   set bottomPos =  getRecPos (me , thisStr , commaPos3 + 1 , thisLength)
  189.   set rightPos =  getRecPos (me , thisStr , commaPos4 + 1 , thisLength)
  190.   --  put "T"&&topPos
  191.   --  put "L"&&leftPos
  192.   --  put "B"&&bottomPos
  193.   --  put "R"&&rightPos&&RETURN
  194.   if ((topPos < vertPos) and (bottomPos > vertPos) and ┬
  195.          (leftPos < horzPos) and (rightPos > horzPos)) then 
  196.     -- we have a click within this rect
  197.     return TRUE
  198.   else
  199.     return FALSE
  200.   end if
  201. end
  202.  
  203. on reset me 
  204.   --put pSprite, pDefaultCast
  205.   set the castNum of sprite pSprite = pDefaultCast
  206.   clearRefLinkIcon me
  207. end